#!/usr/bin/python
# -*- coding: UTF-8 -*-

import base64
import json
import os
import requests

# 具体申请接口请查看
appKey ='d7cqvsjiy2evpszjrlqwjz3qvwqjkorqi7o2xxat'   # appKey
secret ='d3c10b42e7f5b6404e272e2eb1327be5'           # secret Key
userId = "user_id"
deviceId = "IMEI1234567890"
url = "http://api.hivoice.cn/USCService/WebApi?appkey=" + appKey + "&userid=" + userId + "&id=" + deviceId
x_header={
    "Content-Type":"audio/x-wav;codec=pcm;bit=16;rate=16000",
    "Accept":"text/plain",
    "Accept-Language":"zh_CN",
    "Accept-Charset":"utf-8",
    "Accept-Topic":"general"
}
file_address = 'E:\\Users\\10178\\Desktop\\test\\01.wav'
f = open(file_address, 'rb')   
speech = base64.b64encode(f.read()).decode('utf8')
body = {'audio': speech}
req = requests.post(url, data=body, headers=x_header)
print(req)
print (req.text.encode("ISO-8859-1").decode("utf-8"))
# result=json.loads(req.text)
# print(result)
